package com.ebocy.hammer.core.init;

import java.util.List;

import org.apache.log4j.Logger;

import com.ebocy.hammer.core.GameCache;
import com.ebocy.hammer.core.db.DaoManager;
import com.ebocy.hammer.core.db.IDao;
import com.ebocy.hammer.core.domain.Hammer;
import com.ebocy.hammer.core.domain.Item;
import com.ebocy.hammer.core.domain.Rank;
import com.ebocy.hammer.core.domain.Role;
import com.ebocy.hammer.core.domain.Shop;
import com.ebocy.hammer.core.log.EbocyLogManager;

@SuppressWarnings("unchecked")
public class StaticDataLoader {
	private static Logger logger = EbocyLogManager.getSystemLogger();

	private static IDao<Hammer> hammerDao = null;
	private static IDao<Item> itemDao = null;
	private static IDao<Role> roleDao = null;
	private static IDao<Shop> shopDao = null;
	private static IDao<Rank> rankDao = null;

	static {
		hammerDao = DaoManager.getInstance().getDao(Hammer.class);
		itemDao = DaoManager.getInstance().getDao(Item.class);
		roleDao = DaoManager.getInstance().getDao(Role.class);
		shopDao = DaoManager.getInstance().getDao(Shop.class);
		rankDao = DaoManager.getInstance().getDao(Rank.class);
	}

	public static void dataLoader() {
		List<Hammer> hammerList = hammerDao.findAll();
		for (Hammer hammer : hammerList)
			GameCache.hammerData.put(hammer.getHammerId(), hammer);
		hammerList = null;

		List<Item> itemList = itemDao.findAll();
		for (Item item : itemList)
			GameCache.itemData.put(item.getItemId(), item);
		itemList = null;

		List<Role> roleList = roleDao.findAll();
		for (Role role : roleList)
			GameCache.roleData.put(role.getRoleId(), role);
		roleList = null;

		List<Shop> shopList = shopDao.findAll();
		for (Shop shopData : shopList)
			GameCache.shopData.put(shopData.getWaresId(), shopData);
		shopList = null;

		List<Rank> rankList = rankDao.findAll();
		for (Rank randData : rankList)
			GameCache.rankData.put(randData.getRank(), randData);
		rankList = null;
	}
}
